#include <cstdio>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <esp_log.h>
#include <auto_json.h>
#include <map>
#include <driver/uart.h>
#include <hal/uart_ll.h>
#include <driver/gpio.h>
#include <functional>

namespace app
{
    class uart
    {
    public:
        uart(uart_port_t uart_num, gpio_num_t tx, gpio_num_t rx) : uart_num(uart_num), tx_pin(tx), rx_pin(rx) {}

        void start();
        void stop();
        void onReceive(std::function<void(const char *, size_t len)> callback);
        void send(const char *data, size_t len);
        void send(const std::string &data);

    private:
        std::function<void(const char *, size_t len)> receive_callback;
        uart_port_t uart_num = UART_NUM_MAX;
        gpio_num_t tx_pin = GPIO_NUM_MAX;
        gpio_num_t rx_pin = GPIO_NUM_MAX;
    };

};
